#include "channel.h"

// Create a new channel.
Channel::Channel(std::string name)
{
	this->name = name;
}

// Get the name of the channel.
std::string Channel::getName()
{
	return this->name;
}

// Set the topic of the channel.
void Channel::setTopic(std::string topic)
{
	if (!topic.empty())
	{
		this->topic = topic;
	}
}

// Get the topic of the channel.
std::string Channel::getTopic()
{
	return this->topic;
}

// Add a user to the channel.
void Channel::addUser(User *user)
{
	this->users.insert(UserListItem(user->nick, user));
}

// Check to see if the channel has a user.
bool Channel::hasUser(std::string name)
{
	if (this->users.find(name) == this->users.end())
	{
		return false;
	}

	return true;
}

// Get the user from the channel.
User *Channel::getUser(std::string name)
{
	UserListIter it = this->users.find(name);

	if (it == this->users.end())
	{
		return NULL;
	}

	return it->second;
}